package com.zp.self.module.level_1_问道.XI_多线程.AQS;

import org.junit.Test;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2021/3/4 10:20
 * @Modified By
 */
public class ReentrantLock分析 {

    private Lock lock = new ReentrantLock();
    @Test
    public void  code() throws InterruptedException {
        lock.lock();
        lock.tryLock();
        lock.tryLock(1, TimeUnit.MILLISECONDS);
        //柱塞线程，1000纳秒后自动唤醒
        LockSupport.parkNanos(this, 1000);

        Condition condition = lock.newCondition();
        condition.await();
        condition.signal();
        lock.unlock();
    }

}
